package com.ys.malini.web.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import com.ys.malini.dao.IProductDao;
import com.ys.malini.model.TImages;
import com.ys.malini.web.form.ProductForm;

/**
 * 一般产品 ACTION
 * @author Administrator
 *
 */
public class ProductAction extends DispatchAction {

	IProductDao productDao;

	public IProductDao getProductDao() {
		return productDao;
	}

	public void setProductDao(IProductDao productDao) {
		this.productDao = productDao;
	}
	
	/**
	 * 查询所有产品
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward findAllProducts(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		ProductForm formbean = new ProductForm();
		String bclasstype = request.getParameter("b");
		String mclasstype = request.getParameter("m");
		formbean.setBigClassType(bclasstype);
		formbean.setMidClassType(mclasstype);
		
		List<ProductForm> list = productDao.query(formbean,true);
		request.setAttribute("productlist", list);
		if("1".equals(bclasstype)){
			return mapping.findForward("listPage");
		}else if("2".equals(bclasstype)){
			return mapping.findForward("listPage");
		}else if("3".equals(bclasstype)){
			return mapping.findForward("listPage2");
		}
		
		return mapping.findForward("listPage");
		
	}

	/**
	 * 查询单个产品
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward findAllProductById(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		
		String pid = request.getParameter("pid");
		String series = request.getParameter("series");
		ProductForm productdetail = productDao.queryDetailById(pid);
		request.setAttribute("productdetail", productdetail);
		
		List<TImages> imageslist = productDao.queryDetailImagesById(pid);
		request.setAttribute("imageslist", imageslist);
		
		ProductForm formbean = new ProductForm();
		formbean.setProductId(pid);
		formbean.setSeries(series);
		List<ProductForm> list = productDao.queryRelProdById(formbean);
		request.setAttribute("relist", list);
		
		return mapping.findForward("detail");
		
	}

	

}
